﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;

using Optimization.Utilities;

namespace Optimization.StandardProblems
{
    [IsProblem]
    public class Salomon : IProblem
    {
        int dim = 2;

        public Salomon(int dim)
        {
            this.dim = dim;
        }

        public Salomon()
        {
            this.dim = 2;
        }

        static public double Evaluate(Vector v)
        {
            double x2y2 = 0;
            for (int i = 0; i < v.Length; i++)
                x2y2 = x2y2 + v[i] * v[i];
            x2y2 = Math.Sqrt(x2y2);

            double result = 1 + 0.1 * x2y2 - Math.Cos(x2y2);

            return result;
        }

        [CategoryAttribute("Settings"), DescriptionAttribute("Dimension")]
        public int Dim
        {
            get { return dim; }
            set { this.dim = value; }
        }

        double IProblem.Evaluate(Vector v)
        {
            return Evaluate(v);
        }

        void IProblem.GetBounds(out Vector mins, out Vector maxs)
        {
            mins = -30 * Vector.One(dim);
            maxs = +30 * Vector.One(dim);
        }

        bool IProblem.IsFeasible(Vector v)
        {
            return true;
        }

        Vector IProblem.RandomSolution()
        {
            Vector result = Vector.Random(dim, -30, 30);
            return result;
        }
    }
}